package com.micro.modual.extension;

import com.micro.common.MicroConstant;
import com.micro.common.biz.GeneratorCodeUtil;
import com.micro.common.util.SnowFlakeUtil;
import com.micro.modual.entity.User;
import com.micro.modual.model.bo.user.UserBO;

import java.util.Date;

/**
 * <h1>用户基础表 延展类</h1>
 *
 * @author LevelCoder
 * @version V1.0.0
 * @email LevelCoder@126.com
 * @date 2020-08-04 00:23:26
 */
public class UserExtension {

    /**
     * <h2>转换: 用户基础表 新增</h2>
     *
     * @param userBO {@link UserBO} 用户基础表 新增/修改 请求对象
     * @return {@link User} 用户基础表
     */
    public static User converAddUser(UserBO userBO) {
        User user = new User();
        user.setId(SnowFlakeUtil.getId());
        user.setUserCode(userBO.getUserCode());
        user.setUserNickName(userBO.getUserNickName());
        user.setUserEmail(userBO.getUserEmail());
        user.setUserPhone(userBO.getUserPhone());
        user.setUserSex(userBO.getUserSex());
        user.setUserAvatar(userBO.getUserAvatar());
        user.setUserStatus(userBO.getUserStatus());
        user.setUserLastLoginIp(userBO.getUserLastLoginIp());
        user.setUserLastLoginTime(userBO.getUserLastLoginTime());
        user.setPasswordStatus(userBO.getPasswordStatus());
        user.setPasswordSalt(userBO.getPasswordSalt());
        user.setCreateTime(userBO.getCreateTime());
        user.setUpdateTime(userBO.getUpdateTime());
        user.setPaySalt(userBO.getPaySalt());
        user.setPayStatus(userBO.getPayStatus());
        user.setPayPassWord(userBO.getPayPassWord());
        return user;
    }

    /**
     * <h2>转换: 用户基础表 修改</h2>
     *
     * @param userBO {@link UserBO} 用户基础表 新增/修改 请求对象
     * @return {@link User} 用户基础表
     */
    public static User converEditUser(UserBO userBO) {
        User user = new User();
        user.setId(userBO.getId());
        user.setUserCode(userBO.getUserCode());
        user.setUserNickName(userBO.getUserNickName());
        user.setUserEmail(userBO.getUserEmail());
        user.setUserPhone(userBO.getUserPhone());
        user.setUserSex(userBO.getUserSex());
        user.setUserAvatar(userBO.getUserAvatar());
        user.setUserStatus(userBO.getUserStatus());
        user.setUserLastLoginIp(userBO.getUserLastLoginIp());
        user.setUserLastLoginTime(userBO.getUserLastLoginTime());
        user.setPasswordStatus(userBO.getPasswordStatus());
        user.setPasswordSalt(userBO.getPasswordSalt());
        user.setCreateTime(userBO.getCreateTime());
        user.setUpdateTime(userBO.getUpdateTime());
        user.setPaySalt(userBO.getPaySalt());
        user.setPayStatus(userBO.getPayStatus());
        user.setPayPassWord(userBO.getPayPassWord());
        return user;
    }

    /**
     * <h2>初始化用户基础信息:手机号快捷登录</h2>
     * @param userPhone   用户手机号
     * @param userCode    用户编号
     * @return
     */
    public static User initUserForPhoneLogin(String userPhone,String userCode) {
        User user = new User();
        user.setId(SnowFlakeUtil.getId());
        user.setUserCode(GeneratorCodeUtil.generatorCustomerCode());
        user.setPasswordStatus((byte)2);
        user.setUserAvatar(MicroConstant.SystemDefaultValue.DEFAULT_AVATAR);
        user.setCreateTime(new Date());
        user.setUserPhone(userPhone);
        user.setUserStatus((byte)1);
        user.setUserNickName(userPhone);
        user.setUserSex((byte)3);
        return user;
    }
}
